<?php
namespace app\common\request;

use think\Request;

class Base extends Request {
	public function __construct($options = []) {
        parent::__construct($options);
    }

    //请求小程序来源
    public function get_route() {
        $route = $this->header('route');
        $filter = [
            'wechat'     => 'miniprogram',
            'wechat2'    => 'miniprogram2',
            'wechat_oxy' => 'miniprogram_oxy'
        ];
        return isset($filter[$route]) ? $filter[$route] : $route;
    }

    public function get_id() {
        return $this->param('id');
    }

    //获取数据集
    public function post_collection($name, $mustExplode = false) {
        $attrs = $this->post($name);
        if($attrs || $mustExplode) {
            $attrs = explode(',', $attrs);
        }
        return $attrs;
    }

    //获取当前管理员ID
    public function get_admin_id() {
        return 1;
    } 

    //获取当前用户信息
    public function get_current_uid() {
    	$login = loadStorage('Login');
		$user = $login->getCurrentUser();
		return $user ? $user['id'] : '';
    }

    //获取当前店铺信息
    public function get_current_store() {
    	$only = loadOnly('tysj\\Store');
    	return $only->current_store();
    }

    //获取当前店铺ID
    public function get_current_store_id() {
        $store = $this->get_current_store();
        return $store ? $store['id'] : '';
    }

    //获取私有ID数据
    public function get_private_id() {
        $id = $this->get_id();
        $uid = $this->get_current_uid();
        return compact('id', 'uid');
    }

    //获取排序字段
    public function get_order($default = 'id') {
        return $this->param('order', $default);
    }

    //获取排序方式
    public function get_order_type($default = 'desc') {
        return $this->param('order_type', $default);
    }
}
